package com.test.oom;

import java.util.*;

/**
 * describe: 堆内存溢出模拟，设置最大堆为20m，jvisualvm分析堆快照。
 * VM参数：-Xms5m -Xmx20m -XX:+HeapDumpOnOutOfMemoryError -XX:HeapDumpPath=C:\Users\Admin\Desktop\1.hdump -XX:-UseGCOverheadLimit
 *
 * @author lianying
 * @date 2020/01/19
 */
public class HeapOom {
    public static void main(String [] args)
    {
        oom();
    }
    private static void oom(){
        Map<String, Pilot> map = new HashMap<String, Pilot>();
        Object[] array = new Object[1000000];
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        for(int i=0; i<1000000; i++){
            String d = new Date().toString();
            Pilot p = new Pilot(d, i);
            map.put(i+"rosen jiang", p);
            array[i]=p;
        }
    }
}
